package com.sinosoft.hydra.um.domain.model;

import cn.com.sinux.spring.utils.BeanUtils;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/7.
 */
public class LabDataParser {

    private String title;
    private String code;
    private String resultPath;
    private String engine;
    private String parser;
    private String jsonParseType;
    private String parsePage;
    private String encoding = "UTF-8";


    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    private boolean hasChart;

    public boolean isHasChart() {
        return hasChart;
    }

    public void setHasChart(boolean hasChart) {
        this.hasChart = hasChart;
    }

    public int startRowNum = 1;

    public int titleRowNum = 0;
    private int cellsNum = -1;

    public int getCellsNum() {
        return cellsNum;
    }

    public void setCellsNum(int cellsNum) {
        this.cellsNum = cellsNum;
    }

    public int getStartRowNum() {
        return startRowNum;
    }

    public void setStartRowNum(int startRowNum) {
        this.startRowNum = startRowNum;
    }

    public int getTitleRowNum() {
        return titleRowNum;
    }

    public void setTitleRowNum(int titleRowNum) {
        this.titleRowNum = titleRowNum;
    }

    public String getParsePage() {
        return parsePage;
    }

    public void setParsePage(String parsePage) {
        this.parsePage = parsePage;
    }

    private List<String> labels;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    private List<LabDataParser> labDataParsers = new ArrayList<LabDataParser>();


    public static List<LabDataParser> values() {
        return factory.getLabDataParsers();
    }


    public List<LabDataParser> getLabDataParsers() {
        return labDataParsers;
    }

    private static LabDataParser factory;

    public static void destroy() {
        factory = null;
    }

    public static LabDataParser valueOf(String code) {
        if(StringUtils.isNotBlank(code)){
            for (LabDataParser labDataParser : factory.getLabDataParsers()) {
                if (code.equals(labDataParser.getCode())) {
                    LabDataParser dd = new LabDataParser();
                    BeanUtils.copyProperties(labDataParser, dd);
                    return dd;
                }
            }
        }
        return null;
    }

    public static LabDataParser createFactory(List<LabDataParser> labDataParsers) {
        if (factory == null) {
            factory = new LabDataParser();
            factory.getLabDataParsers().addAll(labDataParsers);
        }
        return factory;
    }

    public String getJsonParseType() {
        return jsonParseType;
    }

    public void setJsonParseType(String jsonParseType) {
        this.jsonParseType = jsonParseType;
    }

    public String getResultPath() {
        return resultPath;
    }

    public void setResultPath(String resultPath) {
        this.resultPath = resultPath;
    }

    public String getEngine() {
        return engine;
    }

    public void setEngine(String engine) {
        this.engine = engine;
    }

    public String getParser() {
        return parser;
    }

    public void setParser(String parser) {
        this.parser = parser;
    }

    public List<String> getLabels() {
        return labels;
    }

    public void setLabels(List<String> labels) {
        this.labels = labels;
    }
}
